/** Copyright (c) 2008-2009, Markos Evlogimenos
 *
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 *     * Redistributions of source code must retain the above copyright
 *       notice, this list of conditions and the following disclaimer.
 *     * Redistributions in binary form must reproduce the above copyright
 *       notice, this list of conditions and the following disclaimer in
 *       the documentation and/or other materials provided with the
 *       distribution.
 *     * The name of Markos Evlogimenos may be used to endorse or
 *		 promote products derived from this software without specific
 *		 prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */

package game.packs;

import java.util.Arrays;

import org.kamimark.enums._EnumInterface;

public class FloatPack<ENUMTYPE extends _EnumInterface> implements _Pack<ENUMTYPE>, Comparable<FloatPack<ENUMTYPE>>
{

	private _EnumInterface[] names;
	float[] data;

	public FloatPack(final _EnumInterface[] names) {
		this(names.length);
		this.names = names;
	}

	private FloatPack(final int size) {
		data = new float[size];
	}

	@Override
	public FloatPack<ENUMTYPE> clone() {
		final FloatPack<ENUMTYPE> newPack = new FloatPack<ENUMTYPE>(names.length);
		newPack.names = names;
		newPack.data = data.clone();
		return newPack;
	}

	/**
	 * @param toCompare -
	 *            BoolPack to compare to.
	 * @return
	 *            <ul>
	 *            <li> 1 - All values of the compared object are smaller than the respective values
	 *            of this one.</li>
	 *            <li> 0 - The compared object and this one have the exact same values</li>
	 *            <li> -1 - As not 1</li>
	 *            </ul>
	 */
	public int compareTo(final FloatPack<ENUMTYPE> toCompare) {
		final float[] myData = data;
		final float[] toCompareData = toCompare.data;
		if (Arrays.equals(myData, toCompareData))
			return 0;
		for (byte i = 0; i < myData.length; i++)
			if (myData[i] < toCompareData[i])
				return -1;
		return 1;
	}

	public boolean equals(final FloatPack<ENUMTYPE> toCompare) {
		final float[] myData = data;
		final float[] toCompareData = toCompare.data;
		return Arrays.equals(myData, toCompareData);
	}

	public float[] getElements() {
		return data;
	}

	public _EnumInterface[] getNames() {
		return names;
	}

	@Override
	public String toString() {
		final StringBuilder result = new StringBuilder();
		for (int i = 0; i < names.length; i++) {
			result.append(names[i]);
			result.append(":\t");
			result.append(data[i]);
			result.append("\n");
		}
		return result.toString();
	}

}
